package utils.export;

import java.io.FileWriter;
import java.io.IOException;

public class TXTUtils {
	private static String path = "C:\\Users\\Gary Benattar\\workspace\\GTrend\\Txt\\";
	public static boolean generateTxtFile(String sFilename, String date, String sProportion, String sZscore)
	{
		if(date == null || sProportion == null ||sZscore == null || date == "" || sProportion == "" ||sZscore == "")
			return false;
		try
		{
			FileWriter writer = new FileWriter(path + sFilename + ".dat",true);
			writer.append(sProportion);
			// for gnuplot
			writer.append('\t');
			writer.append(sZscore);
			writer.append("\n");
			writer.flush();
			writer.close();
			return true;
		}
		catch(IOException e)
		{
			e.printStackTrace();
			System.err.println("Error during csv generation");
			return false;
		} 
	}
	
	public static boolean generateTxtFileForJs(String sFilename,String date, String sProportion, String sZscore)
	{
		if(date == null || sProportion == null ||sZscore == null || date == "" || sProportion == "" ||sZscore == "")
			return false;
		try
		{
			FileWriter writer = new FileWriter(path + sFilename + ".txt");
			writer.append(date);
			writer.append(',');
			writer.append(sProportion);
			writer.append(',');
			writer.append(sZscore);
			writer.append("\n");
			writer.flush();
			writer.close();
			return true;
		}
		catch(IOException e)
		{
			e.printStackTrace();
			System.err.println("Error during csv generation");
			return false;
		} 
	}
}
